using System;
using System.Collections;
using System.Threading;
using System.Windows.Forms;
using Microsoft.MediaCenter.AddIn;
using Microsoft.MediaCenter.Extensibility;

namespace ScottLane.VideoInbox.AddIn
{
    /// <summary>
    /// Media Center add-in that displays notification messages to users.
    /// </summary>
    public class BackgroundAddIn : MarshalByRefObject, IAddInModule, IAddInEntryPoint
    {
        private NotificationQueue notifications;
        private ConfigurationSettings settings;

        public void Initialize(IDictionary dictAppInfo, IDictionary dictEntryPoint)
        {
            notifications = new NotificationQueue();
            settings = ConfigurationSettings.Instance;
        }

        public void Launch(AddInHost host)
        {
            while (true)
            {
                if (notifications.Peek() != null)
                {
                    Notification notification = notifications.Remove();

                    if (host.HostControl.Dialog("Play now?", "Video Inbox", 3, 0, true) == 0)
                    {
                        //host.HostControl.PlayMedia(MediaType.Video, notification.Manifest.VideoFileName, false);
                    }
                }

                Thread.Sleep(settings.NotificationQueuePollingInterval);
                Application.DoEvents();
            }
        }

        public bool DisplayDialog(string message)
        {
            return true;
        }

        public void Uninitialize()
        {
        }
    }
}